package cn.edu.uestc.smgt.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.edu.uestc.smgt.pojo.Manager;
import cn.edu.uestc.smgt.pojo.User;

/**
 * 对登录状态的控制
 * 
 * @author Administrator
 *
 */
public class LoginFilter implements Filter {

	public void init(FilterConfig filterConfig) throws ServletException {
		// TODO Auto-generated method stub

	}

	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		// TODO Auto-generated method stub
		HttpServletRequest req = (HttpServletRequest) request;
		HttpServletResponse resp = (HttpServletResponse) response;
		HttpSession session = req.getSession();
		Manager mgr = (Manager) session.getAttribute("manager");
		User user = (User) session.getAttribute("user");
		if (mgr == null && user == null) {
			// 跳转到登录界面
			resp.sendRedirect("/studentmanagement/login.html");
		}
	}

	public void destroy() {
		// TODO Auto-generated method stub

	}

}
